*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*
* Diehl/Wolter: “ATTITUDES ABOUT CONTAINMENT MEASURES DURING
*                THE 2020/2021 CORONAVIRUS PANDEMIC: 
*                SELF-INTEREST, OR BROADER POLITICAL ORIENTATIONS?"
*
* Do-File for regression analysis
*
* This version: 20210602
*
* Author: Felix Wolter, felix.wolter@uni-konstanz.de
*
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


*Final full models, figure 3 and table S4 (supplement)
*Check whether two-dimensional trust indices (political vs. technocratic)
* have different effects.

egen trustpoliti = rowmean(trustbundes* trustland trustparties)
egen trusttechnocr = rowmean(trusthealthsys trustpolice trustscience)

gen doubtpoliti = 8-trustpoliti
gen doubttechnocr = 8-trusttechnocr


reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtpoliti c.doubttechnocr c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==0 //no different effects

estimates store May
ereturn list

reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtpoliti c.doubttechnocr c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==1
   
estimates store November
ereturn list

*20210621: Test trust coefficients against each other
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtpoliti c.doubttechnocr c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [iweight=persweight] if time==0 //no different effects

estimates store May
ereturn list

reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtpoliti c.doubttechnocr c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [iweight=persweight] if time==1
   
estimates store November
ereturn list

suest May November
test [May_mean]doubtpoliti = [November_mean]doubtpoliti
test [May_mean = November_mean]: c.doubtpoliti
lincom [May_mean]doubtpoliti - [November_mean]doubtpoliti
test [May_mean]c.doubttechnocr=[November_mean]c.doubttechnocr
lincom [May_mean]doubttechnocr - [November_mean]doubttechnocr


*Reviewer comment: Share of at-risk group by age
tab riskgroup01 old, col chi2
tab riskgroup01 old [iweight=persweight], col 

bysort time: tab riskgroup01 old, col chi2
bysort time: tab riskgroup01 old [iweight=persweight], col 

	
*Reviewer comment: Correlation matrix: multicollinearity?
pwcorr zopenindex idtecon incloss idtfamily childrenathome  ///
   riskgroup01 old ///
   sttecon sttfamily ///
   doubtstate protransfer leftrightcat ///
   east  ///   
   gentrust ///
   female educyr ///
   kr_inz_rate10 kr_tod_rate10 [aweight=persweight], sig
   
*...self-interest indicators only
bysort time: pwcorr idtecon incloss idtfamily childrenathome riskgroup01 old ///
   [aweight=persweight], sig

*...check VIF
reg zopenindex c.idtecon c.idtfamily  [pweight=persweight] if time==0

estat vif

reg zopenindex c.idtecon c.idtfamily  [pweight=persweight] if time==1

estat vif
	
	
* Estimate VIF to check for multicollinearity in final models
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==0

estat vif

reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==1

estat vif
	
*Check whether effects change if introduced separately into the models
*Re-run main model for May
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==0

gen modelsample1 = e(sample)

*Run bivariate regressions for May
reg zopenindex c.idtecon [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex i.incloss [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.idtfamily [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex i.childrenathome [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex i.riskgroup01 [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex i.old [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.sttecon [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.sttfamily [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.doubtstate [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.protransfer [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex ib2.leftrightcat [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex i.east [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.gentrust [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex i.female [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.educyr [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.kr_inz_rate10 [pweight=persweight] if(time==0 & modelsample1==1)
reg zopenindex c.kr_tod_rate10 [pweight=persweight] if(time==0 & modelsample1==1)

*Re-run main model for November
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==1
   
gen modelsample2 = e(sample)

*Run bivariate regressions for November
reg zopenindex c.idtecon [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex i.incloss [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.idtfamily [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex i.childrenathome [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex i.riskgroup01 [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex i.old [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.sttecon [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.sttfamily [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.doubtstate [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.protransfer [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex ib2.leftrightcat [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex i.east [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.gentrust [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex i.female [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.educyr [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.kr_inz_rate10 [pweight=persweight] if(time==1 & modelsample2==1)
reg zopenindex c.kr_tod_rate10 [pweight=persweight] if(time==1 & modelsample2==1)


*Editor remark: trust variables are probably not confounders, but mediators
*Models without the two trust variables
*Plot all models into one coefplot
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==0

estimates store May
ereturn list

reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==1
   
estimates store November
ereturn list

reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.protransfer ib2.leftrightcat ///
   i.east  ///   
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==0

estimates store Maywithout
ereturn list

reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.protransfer ib2.leftrightcat ///
   i.east  ///   
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==1
   
estimates store Novemberwithout
ereturn list



coefplot (May, msymb(o) mcolor(blue) ciopts(lcolor(blue)) drop(_cons) ) ///
    (November, msymb(t) mcolor(red*1.2) ciopts(lcolor(red*1.2)) drop(_cons) ) ///
	(Maywithout, msymb(x) mcolor(blue) ciopts(lcolor(blue)) drop(_cons) ) ///
	(Novemberwithout, msymb(d) mcolor(red*1.2) ciopts(lcolor(red*1.2)) drop(_cons) ) ///
	, ///
	xline(0, lwidth(medthin) lcolor(black)) ///
    headings(idtecon = "{bf:Individual threat:}" ///
	         sttecon = "{bf:Sociotropic threat:}" ///
			 doubtstate = "{bf:Political orientations:}" ///
			 1.east = "{bf:Control variables:}" ///
			 , labsize(2.5)) ///
	coeflabels(idtfamily = "Family situation" ///
	           1.childrenathome = "Children in household" ///
			   idtecon = "Economic situation" ///
			   1.incloss = "Income loss in pandemic" ///
			   1.riskgroup01 = "Covid-19 at-risk group" ///
			   badhealth = "Bad health" ///
			   1.old = "Age >70" ///
			   sttfamily = "Family situation" ///
			   sttecon = "Economic situation" ///
			   doubtstate = "Low trust in institutions" ///
			   protransfer = "Pro redistribution" ///
			   1.leftrightcat = "Pol. ideol.: left-wing" ///
			   3.leftrightcat = "Pol. ideol.: right-wing" ///
			   4.leftrightcat = "Pol. ideol.: missing" ///
			   gentrust = "General trust" ///
			   1.east = "East Germany" ///
			   1.female = "Gender female" ///
			   educyr = "Education (years)" ///
			   kr_inz_rate10 = "Infections in last 7 days/10K pop." ///
			   kr_tod_rate10 = "Cumulated deaths/10K pop." ///
			   , labsize(2.5)) ///
	xlabel(-.4(.1).4, labsize(2.2)) ylabel(, labsize(2.5)) ///
	plotlabels("May" "November" "May without trust" "November without trust") ///
	graphregion(fcolor(gs15)) ///
    xtitle("Effect on opposition to containments", size(2.5)) legend( size(vsmall)) ///
	ysize(15) xsize(10)
	
	
*Investigate suppression effect of general trust
reg  sttecon c.gentrust ///
   [pweight=persweight] 
   
reg  sttfamily c.gentrust ///
   [pweight=persweight]    

mlogit leftrightcat c.gentrust ///
   [pweight=persweight]    
   
   
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.protransfer ib2.leftrightcat ///
   i.east  ///   
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==0
   
   
*Check effects of self-interest variables if introduced separately along with
*  non-selfinterest variables into the modelsample1
*Re-run main model for May
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==0

gen modelsample3 = e(sample)

*Run regressions for May
reg zopenindex c.idtecon c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==0 & modelsample3==1)
reg zopenindex i.incloss c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==0 & modelsample3==1)
reg zopenindex c.idtfamily c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==0 & modelsample3==1)
reg zopenindex i.childrenathome c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==0 & modelsample3==1)
reg zopenindex i.riskgroup01 c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==0 & modelsample3==1)
reg zopenindex i.old c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==0 & modelsample3==1)
   
*Re-run main model for November
reg zopenindex c.idtecon i.incloss c.idtfamily i.childrenathome  ///
   i.riskgroup01 i.old ///
   c.sttecon c.sttfamily ///
   c.doubtstate c.protransfer ib2.leftrightcat ///
   i.east  ///   
   c.gentrust ///
   i.female c.educyr ///
   c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if time==1
   
gen modelsample4 = e(sample)

*Run regressions for November
reg zopenindex c.idtecon c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==1 & modelsample4==1)
reg zopenindex i.incloss c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==1 & modelsample4==1)
reg zopenindex c.idtfamily c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==1 & modelsample4==1)
reg zopenindex i.childrenathome c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==1 & modelsample4==1)
reg zopenindex i.riskgroup01 c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==1 & modelsample4==1)
reg zopenindex i.old c.sttecon c.sttfamily c.doubtstate c.protransfer ///
   ib2.leftrightcat i.east c.gentrust i.female c.educyr c.kr_inz_rate10 c.kr_tod_rate10 ///
   [pweight=persweight] if (time==1 & modelsample4==1)
   
   
   